import qs from 'qs'
export default {
  data() {
    /* eslint-disable */
        return {
            // 设置属性
            mixinViewModuleOptions: {
                activatedIsNeed: false,    		// 此页面是否在激活（进入）时，调用查询数据列表接口？
                mountedIsNeed: false,    		// 此页面是否在加载时，调用查询数据列表接口？
                getDataListURL: '',       		// 数据列表接口，API地址
                getDataListIsPage: false, 		// 数据列表接口，是否需要分页？
                deleteURL: '',            		// 删除接口，API地址
                deleteIsBatch: false,     		// 删除接口，是否需要批量？
                deleteIsBatchURL: '',     		// 删除接口，批量删除API地址  - 20191018 jtj add
                // deleteIsBatchKey: 'id',   	// 删除接口，批量状态下由那个key进行标记操作？比如：pid，uid...
                deleteIsBatchKey: 'ID',      	// 删除接口，批量状态下由那个key进行标记操作？比如：pid，uid...  20191021 修改 - jtj
                exportURL: '',               	// 导出接口，API地址
                noContent: true,				// 未加载数据加载数据长度为空是否显示 - 20191022 jtj add
                transformFunc: null,       //函数:转化数据来源格式
                filters: [],       
                optimizationOrignData: null,  //后处理原始设计,       
                optimizationBestData: null  //后处理最优设计
            },
            highLightCss:'background:#67c23a;',//高亮背景色
            enableHighLightCss:'background:#ddd;',//高亮禁用变量背景色
            dataForm: {},                // 查询条件
            filterForm: {},
            dataList: [],                   // 数据列表
            filterList: [],
            dataList_all: [],
            list: [],            			    // 分割数据列表到每页
            order: '',                        // 排序，asc／desc
            orderField: '',               // 排序，字段
            page: 1,                        // 当前页码
            limit: 10,                      // 每页数
            total: 0,                       // 总条数
            dataListLoading: false,         // 数据列表，loading状态
            dataListSelections: [],         // 数据列表，多选项
            addOrUpdateVisible: false,      // 新增／更新，弹窗visible状态
            addOrUpdateVisible_model: false,      // 新增／更新，弹窗visible状态
            editVisible: false,              // 修改调用，弹窗visible状态
            resetSampleVisible: false,      // 重置样本弹窗可见性 - 20191014 jtj add
            taskForecastVisible: false,     // 预测任务弹窗可见性 - 20191014 jtj add
            upDataVisible: false,           // 编辑弹窗可见性 - 20191017 jtj add
            upLoadVisible: false,           // 上传弹窗可见性 - 20191017 jtj add
            selectWindVisible: false,		// 选择导入弹窗 - 20191031 jtj add
            selectInfoVisible: false,		// 优化结果弹窗 - 20191223 zny add
            memberManagerVisible: false,
            densityUpdateVisible: false,
            simulationVisible: false,
            updateEnvVisible: false,
            executorVisible:false,
            mirrorVisible:false,
            FiletoVariable:false,
            extractVisible:false,
            menuVisible:false,
            downLoadFileLength: 0        // 文件个数 - 20191106 jtj add
        }
        /* eslint-enable */
  },
  mounted() {
    if (this.mixinViewModuleOptions.mountedIsNeed) {
      this.getDataList()
    }
  },
  activated() {
    if (this.mixinViewModuleOptions.activatedIsNeed) {
      this.getDataList()
    }
  },

  methods: {
    // get 方法 - 常规操作：获取数据列表
    getDataList() {
      this.dataListLoading = true
      this.$http.get(
        this.mixinViewModuleOptions.getDataListURL, {
          params: {
            order: this.order,
            orderField: this.orderField,
            page: this.mixinViewModuleOptions.getDataListIsPage ? this.page : null,
            limit: this.mixinViewModuleOptions.getDataListIsPage ? this.limit : null,
            ...this.dataForm
          }
        }).then(({ data: res }) => {
        this.dataListLoading = false
        // 判断是否正常读取到数据列表
        if (res.ResponseCode !== 0) {
          this.dataList = []
          this.total = 0

          // return this.noteInfoWind({
          //     title: '错误',
          //     message: this.$t(res.ResponseMsg),
          //     type: 'error'
          // });
        }
        // 判断数据列表是否含有数据
        if (res.ResponseContent.length !== 0) {
          this.mixinViewModuleOptions.noContent = false
        } else {
          this.mixinViewModuleOptions.noContent = true
        }

        // 不是排序的情况下重新获取列表数据
        if (!this.order) {
          const func = this.mixinViewModuleOptions.transformFunc
          this.dataList_all = func ? func(res.ResponseContent) : res.ResponseContent
        }
        // console.log(8888, res.ResponseContent);
        // 按照指定长度分割数组
        const startIndex = (this.page - 1) * this.limit
        const endIndex = this.page * this.limit
        const targetArray = this.dataList_all.slice(startIndex, endIndex)

        this.dataList = this.mixinViewModuleOptions.getDataListIsPage ? targetArray : this.dataList_all
        this.total = res.ResponseContent.length
      }).catch(() => {
        this.dataListLoading = false
      })
    },
    // 多选
    dataListSelectionChangeHandle(val) {
      this.dataListSelections = val
    },
    // 降序排列 - add time for 20191024 - jtj
    myDescSort(label) {
      return function(a, b) {
        if (a[label].match(/^[a-zA-Z0-9\u4e00-\u9fa5]+$/g)) { // 判断中文与字母
          return b[label].localeCompare(a[label], 'zh')
        }
        return b[label] - a[label]
      }
    },
    // 升序排列 - add time for 20191024 - jtj
    myAscSort(label) {
      return function(a, b) {
        if (a[label].match(/^[a-zA-Z0-9\u4e00-\u9fa5]+$/g)) { // 判断中文与字母
          return a[label].localeCompare(b[label], 'zh')
        }
        return a[label] - b[label]
      }
    },
    // 排序 - update time for 20191024 - jtj
    dataListSortChangeHandle(data) {
      if (!data.order || !data.prop) {
        this.order = ''
        this.orderField = ''
        return false
      }
      this.order = data.order.replace(/ending$/, '')
      this.orderField = data.prop.replace(/([A-Z])/g, '_$1').toLowerCase()

      if (data.order === 'descending') { // 降序
        this.dataList_all = this.dataList_all.sort(this.myDescSort(data.prop))
      } else if (data.order === 'ascending') { // 升序
        this.dataList_all = this.dataList_all.sort(this.myAscSort(data.prop))
      }
      // 排序后重新分页
      // let startIndex = (this.page - 1) * this.limit;
      // let endIndex = this.page * this.limit;
      // this.dataList = this.dataList_all.slice(startIndex, endIndex);
      this.getDataList()
    },
    // 分页, 每页条数
    pageSizeChangeHandle(val) {
      // console.log("每页条数", val)
      this.page = 1
      this.limit = val
      this.getDataList()
    },
    // 分页, 当前页
    pageCurrentChangeHandle(val) {
      // console.log("当前页", val)
      this.page = val
      this.getDataList()
    },
    // 判断传值是否为空
    nullDataObjParameter(key, displace) {
      var data = key == '' || key == null || key == undefined ? displace : key
      return data
    },
    // 前端行为搜索table中的数据 - 20191119 修改完成
    // 参数说明
    // isValue - 点击搜索按钮事件自身行为 $event
    // reSetObj - 是否重置了变量 Obj
    // filter - 搜索数据 Obj
    dataListSearchHandle(isValue, reSetObj, filter) {
      // 判断传递的参数是否为并配置默认初始值
      // 配置基础数据类别基础参数
      if (reSetObj == '' || reSetObj == null || reSetObj == undefined) {
        var list_self = this.dataList_all // 原始列表
        var list_search = this.filterList // 搜索结果列表
        var list_handle = this.dataList // 搜索结果分页呈现处理 [ 一页只显示 limit 个 ]
        var list_page = this.page // 当前停留页码
        var list_limit = this.limit // 分页限制
        var list_total = this.total // 数据列表统计
      } else {
        var list_self = this.nullDataObjParameter(reSetObj.list, this.dataList_all) // 原始列表
        var list_search = this.nullDataObjParameter(reSetObj.search, this.filterList) // 搜索结果列表
        var list_handle = this.nullDataObjParameter(reSetObj.handle, this.dataList) // 搜索结果分页呈现处理
        var list_page = this.nullDataObjParameter(reSetObj.page, this.page) // 当前停留页码
        var list_limit = this.nullDataObjParameter(reSetObj.limit, this.limit) // 分页限制
        var list_total = this.nullDataObjParameter(reSetObj.total, this.total) // 数据列表统计
      }
      // 配置搜索数据
      var from_filter = this.nullDataObjParameter(filter, this.filterForm)

      // 预设搜索结构标签和内容数组 & 数据起止页
      var arryTag = []
      var arryCon = []
      var startIndex = (list_page - 1) * list_limit
      var endIndex = list_page * list_limit
      // 配置查询数据的 key & value 数组
      for (var tag in from_filter) {
        if (from_filter[tag] != '' && from_filter[tag] != null && from_filter[tag] != undefined) {
          arryTag.push(from_filter[tag])
          arryCon.push(tag)
        }
      }

      if (arryTag.length <= 0) {
        list_total = list_self.length
        // 如果数据有翻页的情况
        list_handle = list_total > list_limit ? list_self.slice(startIndex, endIndex) : list_self
        if (reSetObj == '' || reSetObj == null || reSetObj == undefined) {
          this.dataList = list_handle
        }
        return
      }

      list_search = []
      list_handle = []
      // 是否对值进行判断
      if (isValue) {
        for (var tag in from_filter) {
          list_self.filter(data => {
            Object.keys(data).some(key => {
              if (from_filter[tag] != '' && from_filter[tag] != null && from_filter[tag] != undefined) {
                if (key == tag) {
                  // console.log(8181899, String(data[key]).toLowerCase().indexOf(from_filter[tag]) > -1);
                  if (String(data[key]).includes(from_filter[tag])) {
                    list_search.push(data)
                  }
                }
              }
            })
          })
        }
      } else {
        for (var tag in from_filter) {
          list_self.filter(data => {
            Object.keys(data).some(key => {
              if (from_filter[tag] != '' && from_filter[tag] != null && from_filter[tag] != undefined) {
                if (key == tag) {
                  // console.log(8181899, String(data[key]).toLowerCase().indexOf(from_filter[tag]) > -1);
                  if (String(data[key]).includes(from_filter[tag])) {
                    list_search.push(data)
                  }
                }
              }
            })
          })
        }
      }
      if (arryTag.length > 1) {
        var copyList = list_search
        var copyIds = []
        var newIds = []
        var newList = []
        copyList.map(item => copyIds.push(item.ID))
        copyList.map((item, index, arr) => {
          if (newIds.indexOf(copyIds[index]) == -1) {
            newIds.push(copyIds[index])
          } else {
            newList.push(arr[index])
          }
        })
        list_search = newList
      }
      list_total = list_search.length
      // 如果数据有翻页的情况
      list_handle = list_total > list_limit ? list_search.slice(startIndex, endIndex) : list_search
      if (reSetObj == '' || reSetObj == null || reSetObj == undefined) {
        this.dataList = list_handle
      }
      // console.log(111, 'data_all:', list_self, this.dataList_all, '全部列表' );
      // console.log(222, 'filterList:',list_search, this.filterList, '搜索结果列表');
      // console.log(333, 'dataList:', list_handle, this.dataList, '搜索结果分页列表');
    },
    // filterChangeHandle(val){},
    // 新增 / 修改
    addOrUpdateHandle(id, typeId) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.ID = id || NaN
        if (this.$refs.addOrUpdate.aDataForm) {
          this.$refs.addOrUpdate.aDataForm.ID = id || NaN
        }
        typeId ? this.$refs.addOrUpdate.init(typeId) : this.$refs.addOrUpdate.init()
      })
    },
    // 从首页进行全局布局中新增一个工程/项目 20200106
    // 1、首页新增工程
    addOrUpdateHandle_model(id, typeId) {
      this.addOrUpdateVisible_model = true
      this.$nextTick(() => {
        this.$refs.addOrUpdateModel.dataForm.ID = id
        this.$refs.addOrUpdateModel.init()
      })
    },
    // 2、首页新增工程 - 从工程页面进入
    addModelHandle_model(_modelID) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        if (_modelID) {
          this.$refs.addOrUpdateModel.chooseId = _modelID
        }
        this.$refs.addOrUpdateModel.init()
      })
    },
    // 从文件管理的编辑文件按钮进入，新建输入变量 ———— 暂时无用
    // newInputVariables(fileId){
    //     this.FiletoVariable = true;
    //     this.$nextTick(()=>{
    //         this.$refs.addOrUpdate.dataForm.FileID = fileId;
    //         this.$refs.addOrUpdate.init();
    //     })
    // },
    // 文件管理：输入、输出文件表格中的提取按钮
    extractVarHandle(fid, id) {
      this.extractVisible = true
      this.$nextTick(() => {
        this.$refs.extractVar.dataForm.FileID = fid
        if (id) {
          this.$refs.extractVar.dataForm.ID = id
        }
        this.$refs.extractVar.init()
      })
    },
    // 优化结果弹窗操作
    selectInfoHandle(list) {
      this.selectInfoVisible = true
      this.$nextTick(() => {
        this.$refs.selectInfo.informationDataList = list
        this.$refs.selectInfo.informationNum = list.length
        this.$refs.selectInfo.getinformationDataList()
      })
    },
    // 优化列表详情
    changeInfoHandle(val) {
      this.$nextTick(() => {
        this.$refs.informationDetail.orginData = val
        if (val) { this.$refs.informationDetail.getInfo() }
      })
    },
    // 优化列表历程图
    echartInfoHandle(coord, point, errorPoint, informationList, leftPoint) {
      this.$refs.informationChart.informationList = informationList
      this.$nextTick(() => {
        this.$refs.informationChart.initEchart(coord, point, errorPoint, leftPoint)
      })
    },
    // 优化列表平行坐标图
    echartLineInfoHandle(informationList) {
      this.$refs.informationLineChart.informationList = informationList
      this.$nextTick(() => {
        this.$refs.informationLineChart.InitLineEchart()
      })
    },
    // 添加左侧选中点
    getInformationList(taskId) {
      this.$nextTick(() => {
        this.$refs.informationList.resetEchart(leftPoint)
      })
    },
    // 添加左侧选中点
    resetEchartInfoHandle(leftPoint) {
      this.$nextTick(() => {
        this.$refs.informationChart.resetEchart(leftPoint)
      })
    },
    // 工程新建仿真任务
    createSimulation(_modelID, _name) {
      this.simulationVisible = true
      this.$nextTick(() => {
        this.$refs.Simulation.dataForm.ModelID = _modelID
        this.$refs.Simulation.dataForm.modelName = _name
        this.$refs.Simulation.init()
      })
    },
    // 工程新建执行器
    createExecutor(modelid) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.ModelID = modelid || NaN
        if (this.$refs.addOrUpdate.aDataForm) {
          this.$refs.addOrUpdate.aDataForm.ModelID = modelid || NaN
        }
        this.$refs.addOrUpdate.init()
      })
    },
    // 全局环境变量修改弹窗
    updateEnvHandle(id) {
      this.updateEnvVisible = true
      this.$nextTick(() => {
        this.$refs.updateEnv.dataForm.ID = id || NaN
        this.$refs.updateEnv.init()
      })
    },
    // 从工程页面进入
    addModelHandle(_modelID) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        if (_modelID) {
          this.$refs.addOrUpdate.chooseId = _modelID
        }
        this.$refs.addOrUpdate.init()
      })
    },
    // 工程新建优化问题
    addProblemHandle(_modelID) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.ModelID = _modelID
        this.$refs.addOrUpdate.init()
      })
    },
    // 打开选择导入弹窗
    selectSomethingHandle() {
      this.selectWindVisible = true
      this.$nextTick(() => {
        this.$refs.selectSome.init()
      })
    },
    // 重置样本弹窗可见性 - 20191014 jtj add
    resetSampleHandle(id) {
      this.resetSampleVisible = true
      this.$nextTick(() => {
        this.$refs.resetSample.dataForm.id = id
        this.$refs.resetSample.init()
      })
    },
    // 创建预测任务 - 20191014 jtj add
    taskForecastHandle(id) {
      this.taskForecastVisible = true
      this.$nextTick(() => {
        this.$refs.taskForecast.dataForm.id = id
        this.$refs.taskForecast.init()
      })
    },
    // 提交任务前确认执行器是否存在弹窗
    checkExecutor(id, _isEdit) {
      this.executorVisible = true
      if (_isEdit) {
        this.$nextTick(() => {
          this.$refs.executorAdd.dataForm.ID = id
          this.$refs.executorAdd.init()
        })
      } else {
        this.$nextTick(() => {
          this.$refs.executorAdd.dataForm.ModelID = id
          this.$refs.executorAdd.init()
        })
      }
    },
    // 代码编辑器弹窗可见性 - 20191223 cj add
    mirrorHandle(editType) {
      this.mirrorVisible = true
      this.$nextTick(() => {
        this.$refs.BigMirror.init()
        this.$refs.BigMirror.editType = editType
      })
    },
	    // 编辑弹窗可见性 - 20191014 jtj add
	    upDataHandle(id) {
	      	this.addOrUpdateVisible = true
	      	this.$nextTick(() => {
		        this.$refs.addOrUpdate.dataForm.ID = id
		        this.$refs.addOrUpdate.init()
	      	})
	    },
	    // 在线编辑文本内容弹窗可见性 - 20191014 jtj add
	    upLoadHandle(id, type) {
	      	this.upLoadVisible = true
	      	this.$nextTick(() => {
        this.$refs.upData.dataForm.ID = id
        this.$refs.upData.init()
      })
    },
    transformDoc(content, filename) {
      // 创建隐藏的可下载链接
      var eleLink = document.createElement('a')

      eleLink.download = filename
      eleLink.style.display = 'none'
      // 字符内容转变成blob地址
      var blob = new Blob([content])
      if (blob.size === 0) {
        const warnOption = {
          type: 'warning',
          message: this.$t('上传.未上传文件')
        }
        return this.noteInfoWind(warnOption)
      }

      eleLink.href = URL.createObjectURL(blob)
      // 触发点击
      document.body.appendChild(eleLink)

      eleLink.click()
      // 然后移除
      document.body.removeChild(eleLink)
    },
    // 运行监控-右键菜单
    rightMenuHandle(x, y, data) {
      this.menuVisible = true
      this.$nextTick(() => {
        this.$refs.rightMenu.posX = x
        this.$refs.rightMenu.posY = y
        this.$refs.rightMenu.dataInfo = data
        this.$refs.rightMenu.init()
      })
    },
    // 关闭调用
    edit(id) {
      this.editVisible = true
      this.$nextTick(() => {
        this.$refs.edit.dataForm.id = id
        this.$refs.edit.init()
      })
    },
    memberManagerHandle(id) {
      this.memberManagerVisible = true
      this.$nextTick(() => {
        this.$refs.memberManager.dataForm.id = id
        this.$refs.memberManager.init()
      })
    },
    densityUpdateHandle(id) {
      this.densityUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.densityUpdate.dataForm.id = id
        this.$refs.densityUpdate.init()
      })
    },
    // 页面重刷新
    reLoadAll() {
      this.$router.go(0)
    },
    // post 方法 - 常规操作：删除，单项删除&多选删除 - add for time 20191018 - jtj
    // 参数：1、删除项目 id or ids
    deleteHandle(id) {
      // 如果不符合删除的条件
      if (this.mixinViewModuleOptions.deleteIsBatch && !id && this.dataListSelections.length <= 0) {
        return this.noteInfoWind({
          message: this.$t('提示.批量删除'),
          type: 'warning'
        })
      }
      // 把传进来的参数 id 变为整数形式
      // var _id = parseInt(id);
      id = typeof (id) === 'string' ? parseInt(id) : id
      // 执行删除与批量删除操作
      this.$confirm(this.$t('提示.信息', { 'handle': this.$t('删除') }), this.$t('提示.标题'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        this.$http.post(
          `${id == '' || id == undefined || id == null ? this.mixinViewModuleOptions.deleteIsBatchURL : this.mixinViewModuleOptions.deleteURL}`,
          id == '' || id == undefined || id == null ? {
            'IDs': this.dataListSelections.map(item => item[this.mixinViewModuleOptions.deleteIsBatchKey]),
            'IsDeleteCallUnit': 'auto'
          } : {
            'ID': id,
            'IsDeleteCallUnit': 'auto'
          }
        ).then(({ data: res }) => {
          // if (res.ResponseCode !== 0) {
          //     return this.noteInfoWind({
          //         title: '删除失败',
          //         message: this.$t(res.ResponseMsg),
          //         type: 'error'
          //     });
          // }
          if (res.ResponseCode == 0) {
            var _self = this
            this.noteInfoWind({
              title: this.$t('删除成功'),
              message: this.$t('提示.成功'),
              type: 'success'
            }, 'auto', function() {
              // 判断是否需要整页面刷新
              const _path = _self.$route.path
              if (_path == '/calcmodel-model-list' || _path == '/optProblem-problem-list') {
                _self.reLoadAll()
              } else {
                _self.getDataList()
              }
              // _self.$emit('refreshDataList')
            })
          }
        }).catch(() => { })
      }).catch(() => { })
    },
    // 转换工程类型为中文字符串及标记
    modelTypeStr(typeId) {
      var typeStr = ''
      var typeStr_u = ''
      switch (typeId) {
        case 1:
          typeStr = 'exe'
          typeStr_u = 'E'
          break
        case 2:
          typeStr = 'func'
          typeStr_u = 'F'
          break
        case 3:
          typeStr = 'graph'
          typeStr_u = 'G'
          break
        default:
          typeStr = 'none'
          typeStr_u = 'N'
      }
      return {
        str: typeStr,
        str_u: typeStr_u
      }
    },
    // post 方法 - 常规操作：新建&编辑操作接口数据 - add for time 20191022 - jtj
    // 参数：1、url 接口地址，2、传递服务器数据 ，3、是否为新建工程
    addOrUpdateListInterface(url, data, AddModel) {
      this.$http
        .post(url, data)
        .then(({ data: res }) => {
          // if (res.ResponseCode !== 0) {
          //     return this.noteInfoWind({
          //         title: '失败',
          //         message: this.$t(res.ResponseMsg),
          //         type: 'error'
          //     });
          // }
          if (res.ResponseCode == 0) {
            var _self = this
            this.noteInfoWind({
              title: this.$t('成功'),
              message: this.$t('提示.成功'),
              type: 'success'
            }, 'auto', function() {
              _self.visible = false
              // 页面刷新
              if (AddModel) {
                _self.$store.commit('resetProjectID', res.ResponseContent.ID)
                localStorage.removeItem('problemID')
                localStorage.removeItem('taskID')
                _self.reLoadAll()
              } else {
                _self.$emit('refreshDataList')
              }

              // let _path = _self.$route.path;
              // if (_path == '/calcmodel-model-list') {
              //     _self.reLoadAll();
              // }
              // else {
              //     _self.$emit('refreshDataList');
              // }
              // _self.getDataList();
            })
          }
        })
        .catch(() => { })
    },
    // 升级工程
    upgradeModelHandle(id) {
      if (this.mixinViewModuleOptions.deleteIsBatch && !id && this.dataListSelections.length <= 0) {
        return this.noteInfoWind({
          message: this.$t('提示.批量升级'),
          type: 'warning'
        })
      }
      this.$confirm(this.$t('提示.信息', { 'handle': this.$t('升级') }), this.$t('提示.标题'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        this.$http.delete(
          `${this.mixinViewModuleOptions.deleteURL}${this.mixinViewModuleOptions.deleteIsBatch ? '' : '/' + id}`,
          this.mixinViewModuleOptions.deleteIsBatch ? {
            'data': id ? [id] : this.dataListSelections.map(item => item[this.mixinViewModuleOptions.deleteIsBatchKey])
          } : {}
        ).then(({ data: res }) => {
          // if (res.ResponseCode !== 0) {
          //     return this.noteInfoWind({
          //          message: res.msg,
          //          type: 'error'
          //     })
          // }
          if (res.ResponseCode !== 0) {
            var _self = this
            this.noteInfoWind({
              message: this.$t('提示.成功'),
              type: 'success'
            }, 'auto', function() {
              _self.getDataList()
            })
          }
        }).catch(() => { })
      }).catch(() => { })
    },
    // 导出
    exportHandle() {
      var params = qs.stringify({
        'token': sessionStorage.getItem('token'),
        ...this.dataForm
      })
      window.location.href = `${window.SITE_CONFIG['apiURL']}${this.mixinViewModuleOptions.exportURL}?${params}`
    },
    // 跳转 - 提取到 public 文件中
    // jumpHandle(url, query) {
    //     this.$router.push({ path: url, query: query });
    // },
    selectContent() {
      var startCursor = this.codemirror.getCursor('from') // 选中结束位置
      this.setPosition(startCursor)
    },
    // 按字符匹配
    splitCodeMirror() {
      var cmr = this.codemirror
      if (!cmr.somethingSelected()) return
      var pattern = /\s*[,|;|\t]\s*|\s+/g
      var startCursor = cmr.getCursor('to') // 选中结束位置
      var lineContent = cmr.getLine(startCursor.line) // 所在行内容
      var splitReslut = lineContent.substr(0, startCursor.ch).split(pattern) // 分割结果
      if (splitReslut.length == 0) return
      var count = splitReslut.length - 1// 去除空头尾后的列
      if (splitReslut[count] == '') count--
      var cssRe = this.locationInSplit(lineContent, pattern, count) // 获取获取子字符串在父字符串中的位置
      this.highLight({ line: startCursor.line, ch: cssRe.lineStart }, { line: startCursor.line, ch: cssRe.lineEnd })
      this.setPosition({ line: startCursor.line, ch: count })
    },
    // 获取 str 中以 pattern 分割(split)的第count个点的开始位置与结束位置
    locationInSplit(str, pattern, count) {
      var lineStart = 0
      var lineEnd = 0
      var splitReslut = str.split(pattern)
      var matchReslut = str.match(pattern)
      if (splitReslut.length == 0) return { lineStart: -1, lineEnd: -1 }
      for (var i = 0; i < splitReslut.length; i++) {
        if (i < count) {
          lineStart += splitReslut[i].length + matchReslut[i].length
        } else {
          lineEnd = lineStart + splitReslut[i].length
          break
        }
      }
      return {
        lineStart,
        lineEnd
      }
    },

    // 编辑变量高亮获取 str 中以 pattern 分割(split)的第count个点的开始位置与结束位置
    editLocationInSplit(str, pattern, count) {
      var lineStart = 0
      var lineEnd = 0
      var splitReslut = str.split(pattern)
      var matchReslut = str.match(pattern)
      if (splitReslut.length == 0) return { lineStart: -1, lineEnd: -1 }
      for (var i = 0; i <= count; i++) {
        if (i < count) {
          lineStart += splitReslut[i].length + matchReslut[i].length
        } else {
          lineStart += splitReslut[i].length
          lineEnd = lineStart + matchReslut[i].length
          break
        }
      }
      return {
        lineStart,
        lineEnd
      }
    },
    // 编辑变量高亮已提取变量位置的参数
    editSplitCodeMirror(row, col) {
      var cmr = this.codemirror
      row = parseInt(row)
      if (row < 0) {
        row = cmr.lineCount() + row
      }
      col = parseInt(col)
      var pattern = /\s*[,|;|\t]\s*|\s+/g
      var lineContent = cmr.getLine(row) // 所在行内容
      if (col < 0) {
        var splitReslut = lineContent.substr(0, lineContent.length).split(pattern) // 分割结果
        if (splitReslut.length == 0) return
        var count = splitReslut.length - 1// 去除空头尾后的列
        if (splitReslut[count] == '') count--
        col = count + col
      }
      console.log(row, col)
      var cssRe = this.editLocationInSplit(lineContent, pattern, col) // 获取获取子字符串在父字符串中的位置
      this.highLight({ line: row, ch: cssRe.lineStart }, { line: row, ch: cssRe.lineEnd })
    },
    // 编辑变量高亮已提取变量位置的参数
    editMatchCodeMirror(row, col) {
      var cmr = this.codemirror
      row = parseInt(row)
      if (row < 0) {
        row = cmr.lineCount() + row
      }
      col = parseInt(col)
      var pattern = /[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?/g
      var lineContent = cmr.getLine(row) // 所在行内容5
      if (col < 0) {
        var splitReslut = lineContent.substr(0, lineContent.length).split(pattern) // 分割结果
        if (splitReslut.length == 0) return
        var count = splitReslut.length - 1// 去除空头尾后的列
        if (splitReslut[count] == '') count--
        col = count + col
      }
      console.log(row, col)

      var cssRe = this.editLocationInSplit(lineContent, pattern, col) // 获取获取子字符串在父字符串中的位置
      this.highLight({ line: row, ch: cssRe.lineStart }, { line: row, ch: cssRe.lineEnd })
    },
    // 以match的方式解析内容
    matchCodeMirror() {
      var cmr = this.codemirror
      if (!cmr.somethingSelected()) return
      var pattern = /[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?/g
      var startCursor = cmr.getCursor('to') // 选中结束位置
      var lineContent = cmr.getLine(startCursor.line) // 所在行内容
      var matchReslut = lineContent.substr(0, startCursor.ch).match(pattern) // 匹配结果
      if (matchReslut == null || matchReslut == undefined || matchReslut.length == 0) return
      var count = matchReslut.length - 1// 匹配最后一个
      var cssRe = this.locationInMatch(lineContent, pattern, count) // 获取获取子字符串在父字符串中的位置
      this.highLight({ line: startCursor.line, ch: cssRe.lineStart }, { line: startCursor.line, ch: cssRe.lineEnd })
      this.setPosition({ line: startCursor.line, ch: count })
    },
    // 获取 str 中以 pattern 匹配(match)的第count个点的开始位置与结束位置
    locationInMatch(str, pattern, count) {
      var lineStart = 0
      var lineEnd = 0
      var matchReslut = str.match(pattern)
      var splitReslut = str.split(pattern)
      if (matchReslut.length == 0) return { lineStart: -1, lineEnd: -1 }
      for (var i = 0; i < matchReslut.length; i++) {
        if (i < count) {
          lineStart += splitReslut[i].length + matchReslut[i].length
        } else {
          lineStart += splitReslut[i].length
          lineEnd = lineStart + matchReslut[i].length
          break
        }
      }
      return {
        lineStart,
        lineEnd
      }
    },
    // 高亮变量
    highLight(start, end) {
      var cmr = this.codemirror
      // 去掉原有高亮
      cmr.markText({ line: 0, ch: 0 }, { line: cmr.lineCount(), ch: cmr.getLine(cmr.lineCount() - 1).length }, { css: 'background:transparent;' })
      cmr.markText(start, end, { css: this.highLightCss })// 选中部分增加新高亮
    }
  }
}
